package it.blueocean.acanto.taglibrary.jsp.taglib.tags.dataset;

import it.blueocean.acanto.taglibrary.jsp.taglib.tags.AbstractComponentStateBean;
import it.blueocean.acanto.taglibrary.jsp.taglib.tags.dataset.filter.DatasetFilter;
import it.blueocean.acanto.taglibrary.jsp.taglib.tags.utils.ObjectUtils;

public class PageCachedDataSet extends AbstractComponentStateBean implements DataSet
{
	private static final long serialVersionUID = 8794543164456544L;

	private DataSet dataset_;

	private QueryExecutionResult _result;

	public PageCachedDataSet(DataSet paramDataSet)
	{
		this.dataset_ = paramDataSet;
		setId(paramDataSet.getId());
	}

	public Object[] getRows()
	{
		return getQueryExecutionResult().getRows();
	}

	public Object getRow()
	{
		Object[] arrayOfObject = getRows();
		if(arrayOfObject.length > 0)
			return arrayOfObject[(int) (getCurrentRow() - getFirstRowNumber())];
		return null;
	}

	public String[] getColumnNames()
	{
		return getQueryExecutionResult().getColumnNames();
	}

	public int getAvailablePages()
	{
		if(getResultsPerPage() <= 0)
			return 1;
		return (int) Math.ceil(getAvailableRows() / getResultsPerPage());
	}

	public long getAvailableRows()
	{
		return getQueryExecutionResult().getAvailableRows();
	}

	public int getCurrentPage()
	{
		return this.dataset_.getCurrentPage();
	}

	public long getCurrentRow()
	{
		return this.dataset_.getCurrentRow();
	}

	public String getFilter()
	{
		return this.dataset_.getFilter();
	}

	public long getFirstRowNumber()
	{
		return this.dataset_.getFirstRowNumber();
	}

	public String getOrderBy()
	{
		return this.dataset_.getOrderBy();
	}

	public OrderByClause getOrderByClause()
	{
		return this.dataset_.getOrderByClause();
	}

	public int getResultsPerPage()
	{
		return this.dataset_.getResultsPerPage();
	}

	public void setCurrentPage(int paramInt)
	{
		this.dataset_.setCurrentPage(paramInt);
	}

	public void setCurrentPage(String paramString)
	{
		this.dataset_.setCurrentPage(paramString);
	}

	public void setCurrentRow(int paramInt)
	{
		this.dataset_.setCurrentRow(paramInt);
	}

	public void setCurrentRow(String paramString)
	{
		this.dataset_.setCurrentRow(paramString);
	}

	public void setFilter(String paramString)
	{
		this.dataset_.setFilter(paramString);
	}

	public void setFilter(DatasetFilter paramDatasetFilter)
	{
		this.dataset_.setFilter(paramDatasetFilter);
	}

	public void setFilterAnd(String[] paramArrayOfString)
	{
		this.dataset_.setFilterAnd(paramArrayOfString);
	}

	public void setFilterOr(String[] paramArrayOfString)
	{
		this.dataset_.setFilterOr(paramArrayOfString);
	}

	public void setOrderBy(String paramString)
	{
		this.dataset_.setOrderBy(paramString);
	}

	public void setResultsPerPage(int paramInt)
	{
		this.dataset_.setResultsPerPage(paramInt);
	}

	public void setResultsPerPage(String paramString)
	{
		this.dataset_.setResultsPerPage(paramString);
	}

	public Object getField(int paramInt, String paramString) throws Exception
	{
		Object localObject = getRows()[paramInt];
		return ObjectUtils.getProperty(paramString, localObject);
	}

	public QueryExecutionResult getQueryExecutionResult()
	{
		if(this._result == null)
			this._result = this.dataset_.getQueryExecutionResult();
		return this._result;
	}

	public DatasetFilter getDatasetFilter()
	{
		return this.dataset_.getDatasetFilter();
	}

	public Object getConnection()
	{
		return this.dataset_.getConnection();
	}

	public void setConnection(Object paramObject)
	{
		this.dataset_.setConnection(paramObject);
	}
}
